import {PathDefault} from '../FileList'

export class Pic {
  constructor(file, path = PathDefault) {
    this.imgurl = path + file;
    this.img = new Image();
    this.img.addEventListener('load', () => {
      this.fin = true;
    }, false);
    this.img.src = this.imgurl;
    this.fin = false;
    // this.img.onload = this.loaded();
  }

  loaded() {
    console.log(this.imgurl + '加载完成');
    this.fin = true;
  }

  finished() {
    return this.fin;
  }

  getPic() {
    if (this.fin) {
      return this.img;
    } else {
      return null;
    }
  }

  getWidth() {
    return this.img.width;
  }

  getHeight() {
    return this.img.height;
  }
}
